package com.example.werthwedemo0309.SqlLite;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class weatherHelper extends SQLiteOpenHelper {
    public static final String TABLE_NAME = "city_info";
    public static final String CITY_NAME="name";
    public static final String ID="_id";



    public weatherHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建数据库
        db.execSQL("create table city_info(_id integer primary key autoincrement,name text unique)");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
    public boolean insertStu2(ContentValues values){

        //insert()会返回插入成功后的数据字段ID(即主键自增ID)，如果插入失败则返回-1
        return getWritableDatabase().insert(TABLE_NAME,null,values) != -1;
    }
}
